package com.fjh.springboot_01.controller;

import com.fjh.springboot_01.pojo.Comment;
import com.fjh.springboot_01.pojo.Result;
import com.fjh.springboot_01.service.CommentService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @PostMapping("/add")
    public Result<Comment> addComment(@RequestBody Comment comment) {
        return Result.success(commentService.addComment(comment));
    }

    @GetMapping("/list/{lessonId}")
    public Result<List<Comment>> getComments(@PathVariable Integer lessonId) {
        return Result.success(commentService.getCommentsByLessonId(lessonId));
    }

    @DeleteMapping("/{id}")
    public Result<Void> deleteComment(@PathVariable Integer id) {
        commentService.deleteComment(id);
        return Result.success();
    }
} 